import _thread
import os
import time

from subprocess import Popen, PIPE


def ping_check(ip):
    check = Popen('ping {0}\n'.format(ip), stdin=PIPE, stdout=PIPE, shell=True)
    # print(check)
    # data = check.stdout.read()
    # data = data.decode('gbk')
    #
    # if 'TTL' in data:
    #     print('%s is Up' % ip)


def ip_splie(ip):
    ip_list = ip.split('.')
    ip_masked = ""
    for i, ip in enumerate(ip_list):
        if i < 3:
            if len(ip) == 0:
                return False
            else:
                ip_masked += ip + "."
    return ip_masked


if __name__ == "__main__":
    for i in range(1, 255):
        ip = '10.53.4.' + str(i)
        _thread.start_new_thread(ping_check, (ip,))
    #     time.sleep(0.1)
    ip_splie("1.2.3.4")
